<!-- user表单弹窗 -->
<form id="payCard-form" lay-filter="payCard-form"
	class="layui-form model-form">
	<input name="id" type="hidden" />
	<input name="customerId" type="hidden" />
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">顾客姓名</label>
			<div class="layui-input-block">
				<input name="customerName" type="text" class="layui-input" readonly="readonly" />
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">手机号</label>
			<div class="layui-input-block">
				<input name="customerPhone" type="text" class="layui-input" readonly="readonly" />
			</div>
		</div>
	</div>
	
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">会员服务类型</label>
			<div class="layui-input-block">
				<input name="cardName" type="text" class="layui-input" readonly="readonly" />
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">剩余次数</label>
			<div class="layui-input-block">
				<input name="serviceTimes" type="text" class="layui-input" readonly="readonly" />
			</div>
		</div>
	</div>
	
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">验证码</label>
			<div class="layui-input-block">
				<input id="verificationCode"  name="verificationCode" placeholder="请输入验证码" type="text"
				class="layui-input" />
			</div>
		</div>
		<div class="layui-inline">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" id="smsSend">发送验证码</button>
			</div>
		</div>
	</div>
	
	<div class="layui-form-item model-form-footer">
		<button class="layui-btn layui-btn-primary" type="button"
			ew-event="closeDialog">取消</button>
		<button class="layui-btn" lay-filter="form-submit" lay-submit>保存</button>
	</div>
</form>
<script>
	layui.use([ 'layer', 'admin', 'form', 'formSelects', 'upload' ],
					function() {
						var $ = layui.jquery;
						var layer = layui.layer;
						var admin = layui.admin;
						var form = layui.form;
						var upload = layui.upload;
						var laydate = layui.laydate;
						var formSelects = layui.formSelects;


						var url = 'system/payCard/add';
						// 回显数据
						var payCard = admin.getTempData('t_payCard');
						if (payCard) {
							form.val('payCard-form', payCard);
						}

						// 表单提交事件
						form.on('submit(form-submit)', function(data) {
							var verificationCode = $("#verificationCode").val();
							if(verificationCode.length < 4){
								layer.msg("请正确填写验证码信息");
								return false;
							}
							
							layer.load(2);
							
							payCard.verificationCode = verificationCode;
							admin.req(url, payCard, function(data) {
								layer.closeAll('loading');
								if (data.code == 1) {
									layer.msg(data.msg, {
										icon : 1
									});
									admin.finishPopupCenter();
								} else {
									layer.msg(data.msg, {
										icon : 2
									});
								}
							}, "post");
							return false;
						});
						
						$("#smsSend").click(function () {
							var url = 'system/payCard/sms';
							
							admin.req(url,payCard, function(data) {
								layer.closeAll('loading');
								if (data.code == 1) {
									layer.msg('获取验证码成功');
									time();
								} else {
									layer.msg('获取验证码失败');
								}
							}, "post");
							return false;
						})
					});
	
					var wait=60;
				    function time(){
				    	
				        if (wait==0) {
				        	$("#smsSend").attr("disabled",false); 
				        	$("#smsSend").html("获取验证码");
				        	$("#smsSend").css("background","#fe9900");
				            wait=60;
				        }else{
				        	$("#smsSend").attr("disabled", true);
				        	$("#smsSend").html(wait+"秒后重新获取");
				        	$("#smsSend").css("background","#8f8b8b");
				            wait--;
				            setTimeout(function(){
				                this.time();
				            },1000)
				        }
				    }

</script>